home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Hardware / Mac OS USB DDK / Mac OS USB DDK 1.4.1 / Examples / CompositeClassDriver / ConfigParse.c < prev   
Encoding:
C/C++ Source or Header  |  2000-04-25  |  1.8 KB  |  50 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        ConfigParse.c
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #include <Types.h>
  13. #include <Devices.h>
  14. #include <processes.h>
  15. #include <DriverServices.h>
  16. #include <USB.h>
  17.  
  18. #include "CompositeClassDriver.h"
  19.  
  20. OSErr GetInterfaceDescriptor(LogicalAddress pConfigDesc, UInt32 ReqInterface, USBInterfaceDescriptorPtr * hInterfaceDesc)
  21. {
  22. UInt32 totalLength;
  23. void * pEndOfDescriptors;
  24. USBInterfaceDescriptorPtr     pMyIntDesc;
  25. USBDescriptorHeaderPtr        pCurrentDesc;
  26. unsigned long                anAddress, anOffset;
  27.  
  28.     totalLength = USBToHostWord(((USBConfigurationDescriptorPtr)pConfigDesc)->totalLength);
  29.     pEndOfDescriptors = (Ptr)pConfigDesc + totalLength;                // get the total length and add it to the start of the config space
  30.     pCurrentDesc = (USBDescriptorHeaderPtr)pConfigDesc;                // point the currentdesc to the start of the config space
  31.     
  32.     while (pCurrentDesc < pEndOfDescriptors)                        // as long as we haven't exhausted all the descriptors
  33.     {
  34.         if (pCurrentDesc->descriptorType == kUSBInterfaceDesc)        // look at the current descriptor
  35.         {
  36.             pMyIntDesc = (USBInterfaceDescriptorPtr)pCurrentDesc;    // if it's an interface descriptor
  37.             if (pMyIntDesc->interfaceNumber == ReqInterface)        // see if it's the request descriptor
  38.             {
  39.                 *hInterfaceDesc = pMyIntDesc;                        // if it is, then return with hInterfaceDesc set to the
  40.                 return kUSBNoErr;                                            // current descriptor pointer
  41.             }
  42.         }
  43.         anAddress = (unsigned long) pCurrentDesc;                    // Nope, that either wasn't an interface descriptor
  44.         anOffset  = (unsigned long) pCurrentDesc->length;
  45.         anAddress += anOffset;
  46.         pCurrentDesc = (USBDescriptorHeaderPtr) anAddress;
  47.     }                                                                // or it was, but not the droid we're looking for.
  48.     return -1;
  49. }
  50.